var wx_menu_id = $.query.get('wx_menu_id');
var options={
	page_id:81,
	grid_id:"gridList",
	sqlname:"grid_81_wx_menu_item",
	idField:"uuid",
	parentIdField:"parent_uuid",
	treeField:"menu_name"
};
//document ready
$(function(){
	//初始化搜索条件
	$("input[name='wx_menu_id'").val(wx_menu_id);
	grid1=new uniontrip.treegrid.searchEdit(options);
	$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
	$('#addButton').bind('click', addRow);//新增行绑定事件
	$('#addChildButton').bind('click', addChildRow);//新增行绑定事件
	$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
	$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
	$('#saveButton').bind('click', grid1.accept);//保存treegrid绑定事件
	$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
	$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
	$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
    //$('#setDefaultMenuButton').bind('click', setDefaultMenuButton);//
    //初始化搜索框
    initsearch();
});

/**
 * 新增同级
 */
function addRow(){
	var selectRows=grid1.grid.treegrid('getSelections');
	if(selectRows.length>0){
		var idField=grid1.grid.treegrid('options').idField;
		var parentIdField=grid1.grid.treegrid('options').parentIdField;
		var newRowData={uuid:guid(),wx_menu_id:wx_menu_id};//初始化行数据
		selectRowid=selectRows[0][idField];
		var parent_id=selectRows[0][parentIdField];
		newRowData[parentIdField]=parent_id;
		grid1.grid.treegrid('appendNode',newRowData);
	}else{//新增顶级
		var newRowData={uuid:guid(),wx_menu_id:wx_menu_id};//初始化行数据
		grid1.grid.treegrid('appendNode',newRowData);
	}
}
/**
 * 新增子级
 */
function addChildRow(){
	var selectRows=grid1.grid.treegrid('getSelections');
	if(selectRows.length>0){
		var newRowData={uuid:guid(),wx_menu_id:wx_menu_id};//初始化行数据
		var idField=grid1.grid.treegrid('options').idField;
		var parentIdField=grid1.grid.treegrid('options').parentIdField;
		selectRowid=selectRows[0][idField];
		newRowData[parentIdField]=selectRowid;
		grid1.grid.treegrid('appendNode',newRowData);
	}else{//新增顶级
		var newRowData={uuid:guid(),wx_menu_id:wx_menu_id};//初始化行数据
		grid1.grid.treegrid('appendNode',newRowData);
	}
}

/**
 * 初始化搜索条件
 */
function initsearch(){
	
}

